package com.stylefeng.guns.modular.biz.controller;

import com.baomidou.mybatisplus.plugins.Page;
import com.stylefeng.guns.common.constant.factory.PageFactory;
import com.stylefeng.guns.common.persistence.model.SmsInfo;
import com.stylefeng.guns.common.persistence.model.WorkNotice;
import com.stylefeng.guns.core.base.controller.BaseController;
import com.stylefeng.guns.core.shiro.ShiroKit;
import com.stylefeng.guns.modular.biz.dao.SmsInfoDao;
import com.stylefeng.guns.modular.biz.warpper.SmsInfoWarpper;
import com.stylefeng.guns.modular.biz.warpper.WorkNoticeWarpper;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * 短信信息控制器
 *
 * @author fengshuonan
 * @Date 2017-10-22 11:31:48
 */
@Controller
@RequestMapping("/smsInfo")
public class SmsInfoController extends BaseController {

    private String PREFIX = "/biz/smsInfo/";

    @Resource
    private SmsInfoDao  smsInfoDao;

    /**
     * 跳转到短信信息首页
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "smsInfo.html";
    }

    /**
     * 跳转到添加短信信息
     */
    @RequestMapping("/smsInfo_add")
    public String smsInfoAdd() {
        return PREFIX + "smsInfo_add.html";
    }

    /**
     * 跳转到修改短信信息
     */
    @RequestMapping("/smsInfo_update/{smsInfoId}")
    public String smsInfoUpdate(@PathVariable Integer smsInfoId, Model model) {
        return PREFIX + "smsInfo_edit.html";
    }

    /**
     * 获取短信信息列表
     */
    @RequestMapping(value = "/list")
    @ResponseBody
    public Object list(SmsInfo smsInfo) {
        Page<SmsInfo> page = new PageFactory<SmsInfo>().defaultPage();
        Integer deptid= ShiroKit.getUser().getDeptId();//获取当前用户部门id
        if(ShiroKit.getUser().getDeptId()==27){//超级管理员
            deptid=null;
        }
        List<Map<String, Object>> result = smsInfoDao.getSmsInfos(page ,deptid ,smsInfo.getUserMobile(),smsInfo.getSmsType(),
                smsInfo.getSendStatus(),page.getOrderByField(), page.isAsc()) ;
        page.setRecords((List<SmsInfo>) new SmsInfoWarpper(result).warp());
        return super.packForBT(page);
    }

    /**
     * 新增短信信息
     */
    @RequestMapping(value = "/add")
    @ResponseBody
    public Object add() {
        return super.SUCCESS_TIP;
    }

    /**
     * 删除短信信息
     */
    @RequestMapping(value = "/delete")
    @ResponseBody
    public Object delete() {
        return SUCCESS_TIP;
    }


    /**
     * 修改短信信息
     */
    @RequestMapping(value = "/update")
    @ResponseBody
    public Object update() {
        return super.SUCCESS_TIP;
    }

    /**
     * 短信信息详情
     */
    @RequestMapping(value = "/detail")
    @ResponseBody
    public Object detail() {
        return null;
    }
}
